# 升级到 Python 3.13.x 提高 20% 以上性能
# FROM python:3.13-bullseye
FROM python:3.13-bookworm

# 设定时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# RUN sed -i 's@deb.debian.org@repo.huaweicloud.com@g' /etc/apt/sources.lis && \
#     apt-get update

RUN sed -i 's@deb.debian.org@repo.huaweicloud.com@g' /etc/apt/sources.list.d/debian.sources && \
    apt-get update


RUN pip install \
    scikit-learn scipy pandas aktools akshare jupyterlab \
    PyMySQL \
    -i http://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host=mirrors.aliyun.com  --upgrade

RUN pip install \
    polars sympy matplotlib \
    -i http://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host=mirrors.aliyun.com  --upgrade
    
# ta-lib
COPY ta-lib-0.6.4-src.tar.gz .
RUN tar -xzf ta-lib-0.6.4-src.tar.gz && \
    cd ta-lib-0.6.4/ && \
    ./configure --prefix=/usr && \
    make && \
    make install && \
    cd .. && \
    rm -rf ta-lib-0.6.4 && \
    rm -rf ta-lib-0.6.4-src.tar.gz

RUN pip install \
    ta-lib \
    -i http://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host=mirrors.aliyun.com

# neovim
RUN apt-get install neovim -y

# lsp
RUN pip install \
    python-lsp-server[all] \
    jupyterlab_code_formatter black isort \
    -i http://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host=mirrors.aliyun.com

# node
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

# nvm config for ~/.bashrc, ~/.profile, or ~/.zshrc file
RUN { \
  echo 'export NVM_DIR="$HOME/.nvm"'; \
  echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'; \
  echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion'; \
  } > /root/.bashrc


# install node 12
RUN /bin/bash -c "source /root/.bashrc;NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/ nvm install v22.15.0"

# install lts, sass, sass-convert
# RUN /bin/bash -c "source /root/.bashrc"
# RUN /bin/bash -c "source /root/.bashrc;nvm install --lts"
# RUN /bin/bash -c "source /root/.bashrc;npm install -g sass"
# RUN /bin/bash -c "source /root/.bashrc;npm install apidoc -g"
# RUN /bin/bash -c "source /root/.bashrc;npm install -g sass-convert"

# sqlacodegen Python 版数据库后台表多数据库支持模型后台表生成
RUN pip install \
    sqlacodegen \
    -i http://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host=mirrors.aliyun.com

RUN pip install \
    lckr_jupyterlab_variableinspector \
    -i http://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host=mirrors.aliyun.com

# rust
ENV RUST_VERSION=1.87.0
RUN export RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup; \
    export RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup; \
    curl --proto '=https' --tlsv1.2 -sSf https://mirrors.aliyun.com/repo/rust/rustup-init.sh -o rustup-init;  \
    chmod +x rustup-init; \
    ./rustup-init -y;

# sshd
RUN apt-get install cron supervisor openssh-server -y && \
    rm -rf /var/lib/apt/lists/*

# 创建必要的目录
RUN mkdir -p /var/run/sshd
# 配置 SSH
RUN echo "root:123" | chpasswd && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config

# RUN sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
# ssh-keygen -t dsa -P "" -f /etc/ssh/ssh_host_dsa_key && \
# ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key && \
# ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key && \
# ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key


# 设置国内镜像源
RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple
RUN pip config set install.trusted-host mirrors.aliyun.com

# python fastapi
RUN pip install \
    email-validator==2.2.0 passlib[bcrypt] tenacity==8.5.0 alembic psycopg[binary] \
    sqlmodel bcrypt==4.0.1 pydantic-settings sentry-sdk[fastapi] pyjwt \
    pytest mypy ruff types-passlib==1.7.7.20240819 \
    fastapi[standard] \
    redis[hiredis] \
    loguru \
    emails \
    asyncpg==0.30.0 \
    pydantic-validation-decorator==0.1.4 \
    APScheduler==3.11.0 \
    psycopg2==2.9.10 \
    user-agents==2.2.0 \
    sqlglot[rs]==26.6.0 

# 
RUN pip install \
    py-spy \
    oracledb \
    pymssql \
    cython \
    pyarmor \
    spiffworkflow \
    throttled-py[all] \
    nacos-sdk-python \
    pyinstrument \
    dask[complete] 

# fastapi-event
RUN pip install \
    fastapi-event 

ENTRYPOINT ["supervisord","-n"]